import { Component } from '@angular/core';

declare var ExcelJS: any;

@Component({
  selector: 'app-excel-export',
  standalone: true,
  imports: [],
  templateUrl: './excel-export.component.html',
  styleUrl: './excel-export.component.css'
})
export class ExcelExportComponent {


  constructor() {

    this.export();

  }

  async export() {
    let excelPath = '/device-info/lib/exceljs/dist/exceljs.min.js';
    /* @vite-ignore */
    await import(excelPath);
    const workbook = new ExcelJS.Workbook();
    let sheet = workbook.addWorksheet('海关备案产品汇总表');
    sheet.columns = [
      { header: 'Id', key: 'id', width: 10 },
      { header: 'Name', key: 'name', width: 32 },
      { header: 'D.O.B.', key: 'DOB', width: 10 }
    ]

    const data = [
      [1, 'electron', 'DOB'],
      [2, 'exceljs', 'DOB']
    ];
    sheet.addRows(data);

    let buffer = await workbook.xlsx.writeBuffer();

    const blob = new Blob(buffer);
    const link = document.createElement('a');
    link.download = '海关备案产品汇总表.xlsx';
    link.href = window.URL.createObjectURL(blob);
    link.click();
    window.URL.revokeObjectURL(link.href);

    // let buffer = await workbook.xlsx.write();
    // debugger
    //var aBlob = new Blob( buffer, options );

  }



}
